package com.service.impl;

import com.dao.CartMapper;
import com.model.Cart;
import com.service.CartService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

@Service
public class CartServiceImpl implements CartService {
    @Autowired
    private CartMapper mapper;

    @Override
    public List<Cart> listCart(String userId, Integer businessId) {
        List<Cart> list = new ArrayList<>();
        try {
            list = mapper.listCart(userId,businessId);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return list;

    }
    @Override
    public int saveCart(String userId, Integer businessId, int foodId) {
        int issave=-1;
        try {
            issave=mapper.saveCart(userId,businessId,foodId);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return issave;
    }

    @Override
    public int updateCart(String userId, Integer businessId, int foodId, int quantity) {
        int issave=-1;
        try {
            issave=mapper.updateCart(userId,businessId,foodId,quantity);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return issave;
    }

    @Override
    public int removeCart(String userId, Integer businessId, int foodId) {
        int issave=-1;
        try {
            issave=mapper.removeCart(userId,businessId,foodId);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return issave;
    }

    @Override
    public int removeCart1(String userId, Integer businessId) {
        int issave=-1;
        try {
            issave=mapper.removeCart1(userId,businessId);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return issave;
    }
}
